home *** CD-ROM | disk | FTP | other *** search
- #ifndef __MiscTableBorder_h
- #define __MiscTableBorder_h
- #ifdef __GNUC__
- # pragma interface
- #endif
- //=============================================================================
- //
- // Copyright (C) 1995, 1996 by Paul S. McCarthy and Eric Sunshine.
- // Written by Paul S. McCarthy and Eric Sunshine.
- // All Rights Reserved.
- //
- // This notice may not be removed from this source code.
- //
- // This object is included in the MiscKit by permission from the authors
- // and its use is governed by the MiscKit license, found in the file
- // "License.rtf" in the MiscKit distribution. Please refer to that file
- // for a list of all applicable permissions and restrictions.
- //
- //=============================================================================
- //-----------------------------------------------------------------------------
- // MiscTableBorder.h
- //
- // Structure describing border of an MiscTableView.
- //
- // NOTE: Many of the sub-arrays in an MiscTableBorder are conditional.
- // They are not guaranteed to be allocated for every instance. They are
- // only allocated when the caller tries to store a value in them. Doing
- // a "set" creates the array, even if the value is the default value.
- //
- // "Springy" slots get adjusted when the total size exceeds the global
- // min/max size.
- //
- // NOTE *1* These methods return true if the new value is different than
- // the old value, and the display needs updating.
- //
- // MAINTENANCE NOTE:
- // Consider breaking data_size out of slots into a separate array of
- // its own.
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- // $Id: MiscTableBorder.h,v 1.6 96/01/13 23:39:33 zarnuk Exp $
- // $Log: MiscTableBorder.h,v $
- // Revision 1.6 96/01/13 23:39:33 zarnuk
- // MiscCompareCellFunc -> MiscCompareEntryFunc.
- //
- // Revision 1.5 95/11/12 23:19:53 sunshine
- // Fixed bugs where selection manipulation methods were not checking for valid
- // slot. Fixes bug where selectedSlot() was returning "random" and possibly
- // out-of-range values.
- //
- // Revision 1.4 95/10/08 16:13:14 zarnuk
- // Cell* --> id.
- //
- // Revision 1.3 95/10/04 17:56:48 zarnuk
- // Added do_remap().
- //-----------------------------------------------------------------------------
- #include <misckit/MiscTableScroll.h>
- #include "MiscSparseSet.h"
- #include "MiscTableUtil.h"
-
- extern "Objective-C" {
- #import <objc/Object.h>
- #import <objc/typedstream.h>
- }
-
- @class MiscTableScroll;
- @class Cell;
-
- struct MiscTableSlot
- {
- MiscPixels offset; // Offset of this slot.
- MiscPixels adj_size; // Size adjusted for springy-ness.
- MiscPixels data_size; // Current size of data.
- MiscPixels size; // Target size.
- MiscPixels min_size; // Minimum size.
- MiscPixels max_size; // Maximum size.
- MiscTableSizing sizing; // Sizing options.
- bool isSpringy() const { return ::isSpringy(sizing); }
- bool isData() const { return ::isData(sizing); }
- void read( NXTypedStream* );
- void write( NXTypedStream* );
- };
-
-
- class MiscTableBorder
- {
- private:
- MiscBorderType type; // Row / Col.
- MiscTableScroll* owner;
- MiscTableSlot def_slot; // Default slot configuration.
- int max_slots; // Capacity. Allocation size of arrays.
- int num_slots; // Active number of rows/cols.
- MiscTableSlot* slots; // Indexed by visual coords.
- MiscCoord_P* v2p; // Visual -> Physical coord map.
- MiscCoord_V* p2v; // Physical -> Visual coord map.
- int def_tag; // Default tag value.
- int* tags; // Indexed by physical coords.
- MiscPixels uniform_size; // 0 = not uniform.
- MiscPixels min_total_size; // Min size for the entire border.
- MiscPixels max_total_size; // Max size for the entire border.
- int num_springy; // Number of "springy" slots.
- MiscTableTitleMode title_mode;
- char** titles; // Indexed by visual coords.
- MiscTableCellStyle def_style;
- MiscTableCellStyle* styles;
- id* prototypes;
- MiscCompareEntryFunc* sort_funcs;
- MiscSortDirection* sort_dirs;
- MiscSortType* sort_types;
- MiscSparseSet selection; // Selection (visual coordinates).
- MiscCoord_V cursor; // Keyboard cursor.
- bool selectable; // User can select slot-titles.
- bool sizeable; // User can resize slots.
- bool draggable; // User can rearrange slots.
- bool modifier_drag; // Use modifier key to drag slots.
- bool needs_recalc; // Offset values are "stale".
-
- int shrink_mode( MiscTableSlot& );
- void global_shrink( MiscPixels );
- MiscCoord_V find_springy_slot() const;
- void global_grow( MiscPixels );
- void init_slot( MiscCoord_V, MiscCoord_P );
- void destroy_slot( MiscCoord_V );
- void do_shift( void*, int, int, int );
- void do_shift( MiscCoord_V, MiscCoord_V );
- void* do_remap( void*, int, MiscCoord_V const* );
- void do_remap( MiscCoord_V const* );
- MiscCoord_V find_slot_for_offset( MiscPixels );
-
- void perform_recalc();
- void do_recalc();
- void recalc_if_needed();
- int alloc_size( int rec_size );
- void* do_alloc( int );
- void* do_alloc_init( int );
- void* do_realloc( void*, int );
- void do_realloc();
- void do_delete( void*, int, int );
- void do_delete( MiscCoord_V, MiscCoord_P );
- void do_insert( void*, int, int );
- void do_insert( MiscCoord_V, MiscCoord_P );
- void alloc_slots();
- void alloc_vmap();
- void alloc_titles();
- void dealloc_titles();
- void alloc_tags();
- void alloc_styles();
- void alloc_prototypes();
- id new_prototype( MiscCoord_V );
- void alloc_sort_funcs();
- void alloc_sort_dirs();
- void alloc_sort_types();
-
- char const* get_title( MiscCoord_V ) const;
- id get_prototype( MiscCoord_V ) const;
-
- void selected_slots(MiscIntList* list, bool do_tags) const;
- bool good_int_map( int const* map ) const;
-
- public:
- MiscTableBorder( MiscBorderType );
- ~MiscTableBorder();
-
- MiscTableScroll* getOwner() const { return owner; }
- void setOwner( MiscTableScroll* );
-
- int count() const { return num_slots; }
- int capacity() const { return max_slots; }
- void setCount( int );
- void setCapacity( int );
- void freeExtraCapacity();
- void empty();
- void emptyAndFree() { empty(); freeExtraCapacity(); }
-
- void deleteAt( MiscCoord_V );
- void insertAt( MiscCoord_V, MiscCoord_P );
- void add() { insertAt(count(),count()); }
- void moveFromTo( MiscCoord_V, MiscCoord_V );
-
- MiscSparseSet& selectionSet() { return selection; }
- MiscTableSlot const* getSlots() const { return slots; }
- MiscCoord_V const* getVMap() const { return p2v; }
- MiscCoord_P const* getPMap() const { return v2p; }
- void setSlotSizes( MiscPixels const* );
- bool goodVMap( MiscCoord_P const* map ) const;
- bool goodPMap( MiscCoord_P const* map ) const;
- bool setVMap( MiscCoord_P const* );
- bool setPMap( MiscCoord_V const* );
- void clearVMap();
-
- MiscBorderType getType() const { return type; }
- bool isColBorder() const { return type == MISC_COL_BORDER; }
- bool isRowBorder() const { return type == MISC_ROW_BORDER; }
- bool isSelectable() const { return selectable; }
- bool isSizeable() const { return sizeable; }
- bool isDraggable() const { return draggable; }
- bool isModifierDrag() const { return modifier_drag; }
- bool isUniformSize() const { return uniform_size != 0; }
- MiscPixels getUniformSize() const { return uniform_size; }
- MiscTableTitleMode getTitleMode() const { return title_mode; }
- bool needsRecalc() const { return needs_recalc; }
-
- void setType( MiscBorderType );
- void setDraggable( bool x ) { draggable = x; }
- void setModifierDrag( bool x ) { modifier_drag = x; }
- void setSelectable( bool x ) { selectable = x; }
- void setSizeable( bool x ) { sizeable = x; }
- bool setUniformSize( MiscPixels ); // NOTE *1*
- bool setTitleMode( MiscTableTitleMode ); // NOTE *1*
-
- MiscPixels totalSize();
- MiscPixels getMinTotalSize() const { return min_total_size; }
- MiscPixels getMaxTotalSize() const { return max_total_size; }
- void setMinTotalSize( MiscPixels );
- void setMaxTotalSize( MiscPixels );
-
- MiscCoord_P visualToPhysical( MiscCoord_V x ) const
- { return (v2p != 0) ? v2p[x] : (MiscCoord_P)x; }
- MiscCoord_V physicalToVisual( MiscCoord_P x ) const
- { return (p2v != 0) ? p2v[x] : (MiscCoord_V)x; }
- MiscCoord_V visualForOffset( MiscPixels );
- void recalcOffsets();
-
- MiscPixels getOffset( MiscCoord_V );
- MiscPixels getSize( MiscCoord_V ) const; // target size.
- MiscPixels getMinSize( MiscCoord_V ) const;
- MiscPixels getMaxSize( MiscCoord_V ) const;
- MiscPixels getDataSize( MiscCoord_V ) const;
- MiscPixels effectiveSize( MiscCoord_V ); // adj_size.
- MiscPixels effectiveMaxSize( MiscCoord_V ); // With global
- MiscPixels effectiveMinSize( MiscCoord_V ); // limts.
- char const* getTitle( MiscCoord_V ) const;
- int getTag( MiscCoord_V ) const;
- MiscTableCellStyle getStyle( MiscCoord_V ) const;
- id getPrototype( MiscCoord_V );
- MiscCompareEntryFunc getSortFunc( MiscCoord_V ) const;
- MiscSortDirection getSortDirection( MiscCoord_V ) const;
- MiscSortType getSortType( MiscCoord_V ) const;
- MiscTableSizing getSizing( MiscCoord_V ) const;
- bool isFixed( MiscCoord_V x ) const
- { return ::isFixed(getSizing(x)); }
- bool isSpringy( MiscCoord_V x ) const
- { return ::isSpringy(getSizing(x)); }
- bool isSizeable( MiscCoord_V x ) const
- { return ::isSizeable(getSizing(x)); }
- bool isData( MiscCoord_V x ) const
- { return ::isData(getSizing(x)); }
-
- void setSize( MiscCoord_V, MiscPixels );
- void setMinSize( MiscCoord_V, MiscPixels );
- void setMaxSize( MiscCoord_V, MiscPixels );
- void setDataSize( MiscCoord_V, MiscPixels );
- bool setTitle( MiscCoord_V, char const* ); // NOTE *1*
- void setTag( MiscCoord_V, int );
- void setStyle( MiscCoord_V, MiscTableCellStyle );
- void setPrototype( MiscCoord_V, id );
- void setSortFunc( MiscCoord_V, MiscCompareEntryFunc );
- void setSortDirection( MiscCoord_V, MiscSortDirection );
- void setSortType( MiscCoord_V, MiscSortType );
- void setSizing( MiscCoord_V, MiscTableSizing );
- void setSpringy( MiscCoord_V x, bool b )
- { setSizing( x, ::setSpringy(getSizing(x),b) ); }
- void setSizeable( MiscCoord_V x, bool b )
- { setSizing( x, ::setSizeable(getSizing(x),b) ); }
- void setData( MiscCoord_V x, bool b )
- { setSizing( x, ::setData(getSizing(x),b) ); }
-
- // Default values are used to initialize new slots.
- MiscPixels getDefaultSize() const { return def_slot.size; }
- MiscPixels getDefaultMinSize() const { return def_slot.min_size; }
- MiscPixels getDefaultMaxSize() const { return def_slot.min_size; }
- MiscTableSizing getDefaultSizing() const { return def_slot.sizing; }
- int getDefaultTag() const { return def_tag; }
- MiscTableCellStyle getDefaultStyle() const{ return def_style; }
-
- void setDefaultSize( MiscPixels x )
- { needs_recalc = true; def_slot.size = x; }
- void setDefaultMinSize( MiscPixels x )
- { needs_recalc = true; def_slot.min_size = x; }
- void setDefaultMaxSize( MiscPixels x )
- { needs_recalc = true; def_slot.max_size = x; }
- void setDefaultSizing( MiscTableSizing x )
- { needs_recalc = true; def_slot.sizing = x; }
- void setDefaultTag( int x ) { def_tag = x; }
- void setDefaultStyle( MiscTableCellStyle x )
- { def_style = x; }
-
- // Programmatic selection interface using physical-cooridnates.
- bool hasSelection() const { return !selection.isEmpty(); }
- bool hasMultipleSelection() const;
- unsigned int numSelected() const { return selection.count(); }
- bool slotIsSelected( MiscCoord_P s ) const;
- MiscCoord_P selectedSlot() const;
- void selectedSlots( MiscIntList* l ) const { selected_slots(l,false); }
- void selectedTags( MiscIntList* l ) const { selected_slots(l,true); }
- void selectSlot( MiscCoord_P s );
- void selectSlots( MiscIntList* );
- void selectTags( MiscIntList* );
- void selectAll() { if (count() > 0) selection.add( 0, count() - 1 ); }
- void selectNone() { selection.empty(); }
-
- // Programmatic keyboard cursor interface using visual-cooridnates.
- MiscCoord_V getCursor() const { return cursor; }
- void setCursor( MiscCoord_V c )
- { if (c >= 0 && c < count()) cursor = c; }
- void clearCursor() { setCursor(-1); }
- bool hasValidCursor() const { return cursor >= 0 && cursor < count(); }
-
- // Physical-coordinate convenience methods.
- void deleteAt_P( MiscCoord_P x )
- { deleteAt( physicalToVisual(x) ); }
- MiscPixels getOffset_P( MiscCoord_P x )
- { return getOffset( physicalToVisual(x) ); }
- MiscPixels effectiveSize_P( MiscCoord_P x )
- { return effectiveSize( physicalToVisual(x) ); }
- MiscPixels getSize_P( MiscCoord_P x ) const
- { return getSize( physicalToVisual(x) ); }
- MiscPixels getMinSize_P( MiscCoord_P x ) const
- { return getMinSize( physicalToVisual(x) ); }
- MiscPixels getMaxSize_P( MiscCoord_P x ) const
- { return getMaxSize( physicalToVisual(x) ); }
- MiscPixels getDataSize_P( MiscCoord_P x ) const
- { return getDataSize( physicalToVisual(x) ); }
- char const* getTitle_P( MiscCoord_P x ) const
- { return getTitle( physicalToVisual(x) ); }
- int getTag_P( MiscCoord_P x ) const
- { return getTag( physicalToVisual(x) ); }
- MiscTableCellStyle getStyle_P( MiscCoord_P x ) const
- { return getStyle( physicalToVisual(x) ); }
- id getPrototype_P( MiscCoord_V x )
- { return getPrototype( physicalToVisual(x) ); }
- MiscCompareEntryFunc getSortFunc_P( MiscCoord_V x ) const
- { return getSortFunc( physicalToVisual(x) ); }
- MiscSortDirection getSortDirection_P( MiscCoord_V x ) const
- { return getSortDirection( physicalToVisual(x) ); }
- MiscSortType getSortType_P( MiscCoord_V x ) const
- { return getSortType( physicalToVisual(x) ); }
- MiscTableSizing getSizing_P( MiscCoord_P x ) const
- { return getSizing( physicalToVisual(x) ); }
- bool isFixed_P( MiscCoord_P x ) const
- { return ::isFixed(getSizing_P(x)); }
- bool isSpringy_P( MiscCoord_P x ) const
- { return ::isSpringy(getSizing_P(x)); }
- bool isSizeable_P( MiscCoord_P x ) const
- { return ::isSizeable(getSizing_P(x)); }
- bool isData_P( MiscCoord_P x ) const
- { return ::isData(getSizing_P(x)); }
-
- void setSize_P( MiscCoord_P x, MiscPixels y )
- { setSize( physicalToVisual(x), y ); }
- void setMinSize_P( MiscCoord_P x, MiscPixels y )
- { setMinSize( physicalToVisual(x), y ); }
- void setMaxSize_P( MiscCoord_P x, MiscPixels y )
- { setMaxSize( physicalToVisual(x), y ); }
- void setDataSize_P( MiscCoord_P x, MiscPixels y )
- { setDataSize( physicalToVisual(x), y ); }
- bool setTitle_P( MiscCoord_P x, char const* y )
- { return setTitle( physicalToVisual(x), y ); }
- void setTag_P( MiscCoord_P x, int y )
- { setTag( physicalToVisual(x), y ); }
- void setStyle_P( MiscCoord_P x, MiscTableCellStyle y )
- { setStyle( physicalToVisual(x), y ); }
- void setPrototype_P( MiscCoord_P x, id y )
- { setPrototype( physicalToVisual(x), y ); }
- void setSortFunc_P( MiscCoord_P x, MiscCompareEntryFunc y )
- { setSortFunc( physicalToVisual(x), y ); }
- void setSortDirection_P( MiscCoord_P x, MiscSortDirection y )
- { setSortDirection( physicalToVisual(x), y ); }
- void setSortType_P( MiscCoord_P x, MiscSortType y )
- { setSortType( physicalToVisual(x), y ); }
- void setSizing_P( MiscCoord_P x, MiscTableSizing y )
- { setSizing( physicalToVisual(x), y ); }
- void setSpringy_P( MiscCoord_P x, bool y )
- { setSpringy( physicalToVisual(x), y ); }
- void setSizeable_P( MiscCoord_P x, bool y )
- { setSizeable( physicalToVisual(x), y ); }
- void setData_P( MiscCoord_P x, bool y )
- { setData( physicalToVisual(x), y ); }
-
- void setCursor_P( MiscCoord_P c ) { setCursor(physicalToVisual(c)); }
- MiscCoord_P getCursor_P() const
- { return visualToPhysical(getCursor()); }
-
- // Archiving support.
- void write( NXTypedStream* );
- void read( NXTypedStream* );
- };
-
- #endif // __MiscTableBorder_h
-